function edit_Name(my) {
    var i = my;
    var hint_Null = document.getElementsByClassName("hint_Null");
    if (i.getAttribute("class") == "edit_Name"){
        var administrator_Name = $(".administrator_Name");
        administrator_Name.html('<input type="text" class="name">')
        i.setAttribute("class", "finish_Name");
        i.innerText = "完成"
    }else if (i.getAttribute("class") == "finish_Name"){
        var name = $(".name");
        if (name.val().trim() != "" && name.val().length <= 8){
            var administrator_Name = $(".administrator_Name");
            administrator_Name.html('<span class="administrator_Name">'+name.val()+'</span>')
            i.setAttribute("class", "edit_Name");
            i.innerText = "编辑"
            hint_Null[0].style.display = "none"
            hint_Null[0].innerText = ""
        }else if (name.val().length > 8){
            hint_Null[0].innerText = "输入的名字不能超过8个字！"
            hint_Null[0].style.display = "block"
        } else{
            hint_Null[0].innerText = "输入的名字不能为空！"
            hint_Null[0].style.display = "block"
        }
    }
}
function select_All() {
    var one = document.getElementsByClassName("one");
    var frame = document.getElementsByClassName("frame");
    if (one[0].getAttribute("all") == "true"){
        for (let i = 0; i < frame.length; i++) {
            if (frame[i].getAttribute("itselected") == "false"){
                frame[i].checked = true;
                frame[i].setAttribute("itselected","true")
            }
        }
        one[0].setAttribute("all","false")
    }else if (one[0].getAttribute("all") == "false"){
        for (let i = 0; i < frame.length; i++) {
            if (frame[i].getAttribute("itselected") == "true"){
                frame[i].checked = false;
                frame[i].setAttribute("itselected","false")
            }
        }
        one[0].setAttribute("all","true")
    }
}
function single(my) {
    var i = my;
    var no = 0 ;
    var yes = 0 ;
    var single = document.getElementsByClassName("single")
    for (let i = 0; i < single.length; i++) {
        if (single[i].getAttribute("itselected") == "true"){
            no+=1;
        }else{
            yes+=1;
        }
    }
    var one = document.getElementsByClassName("one")
    if (no == single.length){
        one[0].setAttribute("all","true")
        one[0].checked = false;
    }else if(yes < single.length){
        one[0].setAttribute("all","false")
        one[0].checked = true;
    }
    if (i.getAttribute("itselected") == "true"){
        i.setAttribute("itselected","false")
    }else{
        i.setAttribute("itselected","true")
    }
}

function radio(my) {
    var my1 = my;
    if (my1.getAttribute("itselected")=="false"){
        my1.setAttribute("itselected","true")
    }else{
        my1.setAttribute("itselected","false")
    }
    var all_Body = document.getElementsByClassName("all_Body")
    var sun = 0;
    for (let i = 0; i < all_Body.length; i++) {
        if(all_Body[i].getAttribute("itselected") == "false"){
            sun+= 1;
        }
    }
    var all_Head = document.getElementsByClassName("all_Head")
    console.log(sun)
    if (sun == 0){
        all_Head[0].setAttribute("all","false")
        all_Head[0].checked = true;
    }else{
        all_Head[0].setAttribute("all","true")
        all_Head[0].checked = false;
    }
}

function specify(index) {
    var list_table = document.getElementsByClassName("list_table")
    for (let i = 0; i < list_table.length; i++) {
        list_table[i].style.display = "none"
    }

    var pages = document.getElementsByClassName("pages"+index)
    pages[0].style.display = "block"
}
function specify_Left(index) {
    if (index == 1){
        var list_table = document.getElementsByClassName("list_table")
        for (let i = 0; i < list_table.length; i++) {
            if (list_table[i].style.display == "block"){
                if (i != 0){
                    list_table[i].style.display = "none";
                    list_table[i-1].style.display = "block";
                }
                break
            }
        }
    }else if (index == 2){
        var list_Pages = document.getElementsByClassName("list_Pages")
        for (let i = 0; i < list_Pages.length; i++) {
            if (list_Pages[i].style.display == "block"){
                if (i != 0){
                    list_Pages[i].style.display = "none";
                    list_Pages[i-1].style.display = "block";
                }
                break
            }
        }
        examination()
    }
}
function specify_Right(index) {
    if (index == 1){
        var list_table = document.getElementsByClassName("list_table")
        for (let i = 0; i < list_table.length; i++) {
            if (list_table[i].style.display == "block"){
                if (i < list_table.length-1){
                    list_table[i].style.display = "none";
                    list_table[i+1].style.display = "block";
                }
                break
            }
        }
    }else if (index == 2){
        var list_Pages = document.getElementsByClassName("list_Pages")
        for (let i = 0; i < list_Pages.length; i++) {
            if (list_Pages[i].style.display == "block"){
                if (i < list_Pages.length-1){
                    list_Pages[i].style.display = "none";
                    list_Pages[i+1].style.display = "block";
                }
                break
            }
        }
        examination()
    }
}
function this_All() {
    var this_All = document.getElementsByClassName("this_All")
    var list_table = document.getElementsByClassName("list_table");
    var one = document.getElementsByClassName("one")
    if (this_All[0].getAttribute("state") == "true"){
        for (let i = 0; i < list_table.length; i++) {
            if (list_table[i].style.display == "block"){
                var Select_this = document.getElementsByClassName("Select_this"+(i+1))
                for (let j = 0; j < Select_this.length; j++) {
                    Select_this[j].checked = true
                    Select_this[j].setAttribute("itselected","true")
                }
                this_All[0].setAttribute("state","false")
                break
            }
        }
        var single = document.getElementsByClassName("single")

        var sun = 0 ;
        var arr = [];
        for (let i = 0; i < single.length; i++) {
            sun+=1
            if(single[i].getAttribute("itselected")== "true"){
                arr[sun] = i;
            }
        }
        console.log([...new Set(arr)])
        //set去重
        if(arr.length == 16){
            one[0].setAttribute("all","false")
            one[0].checked = true;
        }
    }else if (this_All[0].getAttribute("state") == "false"){
        for (let i = 0; i < list_table.length; i++) {
            if (list_table[i].style.display == "block"){
                var Select_this = document.getElementsByClassName("Select_this"+(i+1))
                for (let j = 0; j < Select_this.length; j++) {
                    Select_this[j].checked = false
                    Select_this[j].setAttribute("itselected","false")
                }
                this_All[0].setAttribute("state","true")
                break
            }
        }
        one[0].setAttribute("all","true")
        one[0].checked = false;
    }
}
var row = null;
var this_Img = null
var correspond = 0 ;
var input_Yes_No = null
function prompt_Display(value,e){
    var hint_Remove = document.getElementsByClassName("hint_Remove")
    hint_Remove[0].style.display = "block"
    var remove_Word = document.getElementsByClassName("remove_Word")
    if (value == 1){
        remove_Word[0].innerText = "确认发货所选商品吗？"
        correspond = 1;
    }else if (value == 2){
        remove_Word[0].innerText = "确认删除所选商品吗？"
        correspond = 2;
    }else if (value == 3){
        remove_Word[0].innerText = "确认下架所选商品吗？"
        var tar = e.target
        input_Yes_No = tar.parentNode.parentNode.firstChild.firstChild
        if (input_Yes_No.checked == true){
            correspond = 2;
        }else{
            correspond = 3;
            this_Img = tar;
            row = tar.parentNode.parentNode;
        }
    }else if (value == 4){
        remove_Word[0].innerText = "确认修改此商品吗？"
        correspond = 4;
    }else if (value == 5){
        var tar = e.target
        remove_Word[0].innerText = "确认上架此商品吗？"
        input_Yes_No = tar.parentNode.parentNode.firstChild.firstChild
        if (input_Yes_No.checked == true){
            correspond = 6;
        }else{
            correspond = 5;
            this_Img = tar;
            row = tar.parentNode.parentNode;
        }
    }
}
function prompt_Disappear(index) {
    var all_Body = document.getElementsByClassName("all_Body")
    var hint_Remove = document.getElementsByClassName("hint_Remove")
    if (index == 1){
        hint_Remove[0].style.display = "none"
    }else if (index == 2){
        hint_Remove[1].style.display = "none"
    }else{
        if (correspond == 6){
            for (let i = 0; i < all_Body.length; i++) {
                if (all_Body[i].checked == true){
                    var father = all_Body[i].parentNode.parentNode
                    father.style.backgroundColor = "#FFF"
                    var img = father.lastElementChild.firstElementChild
                    img.src ="/Web_img/take_Down.png"
                    img.title = "下架商品"
                    img.setAttribute("onclick","prompt_Display(3,event)")
                }
            }
        } else if (correspond == 5){
            row.style.backgroundColor = "#FFF"
            this_Img.src ="/Web_img/take_Down.png"
            this_Img.title = "下架商品"
            this_Img.setAttribute("onclick","prompt_Display(3,event)")
        } else if (correspond == 4) {
            hint_Remove[1].style.display = "block"
        }else if (correspond == 3){
            row.style.backgroundColor = "#F5F5F5"
            this_Img.src ="/Web_img/take_Up.png"
            this_Img.title = "上架商品"
            this_Img.setAttribute("onclick","prompt_Display(5,event)")
        }else if (correspond == 2){
            for (let i = 0; i < all_Body.length; i++) {
                if (all_Body[i].checked == true){
                    var father = all_Body[i].parentNode.parentNode
                    father.style.backgroundColor = "#F5F5F5"
                    var img = father.lastElementChild.firstElementChild
                    img.src ="/Web_img/take_Up.png"
                    img.title = "上架商品"
                    img.setAttribute("onclick","prompt_Display(5,event)")
                }
            }
        }
        hint_Remove[0].style.display = "none"
    }
}

function zoom(my){
    var remove_Text = document.getElementsByClassName("remove_Text")
    remove_Text[1].style.display = "none"
    var zoom = document.getElementsByClassName("zoom")
    var i = my
    var img = document.createElement("img");
    img.className = "zoom_Img"
    img.src = i.src;
    img.setAttribute("ondblclick","lessen()");
    zoom[0].appendChild(img);
}
function lessen() {
    var zoom = document.getElementsByClassName("zoom")
    var zoom_Img = zoom[0].firstChild;
    var remove_Text = document.getElementsByClassName("remove_Text")
    remove_Text[1].style.display = "block";
    zoom_Img.remove();
}
function corresponding_Page(index) {
    var correspond_Content = document.getElementsByClassName("correspond_Content")
    var order_View = document.getElementsByClassName("order_View")
    var commodity = document.getElementsByClassName("commodity")
    correspond_Content[0].style.display = "none"
    order_View[0].style.display = "none"
    commodity[0].style.display = "none"
    if (index == 1){
        correspond_Content[0].style.display = "block"
    }else if (index == 2){
        order_View[0].style.display = "block"
    }else if (index == 3){
        commodity[0].style.display = "block"
    }
}
function all2() {
    var all_Head = document.getElementsByClassName("all_Head");
    var all_Body = document.getElementsByClassName("all_Body");
    if (all_Head[0].getAttribute("all") == "true"){
        for (let i = 0; i < all_Body.length; i++) {
            if (all_Body[i].getAttribute("itselected") == "false"){
                all_Body[i].checked = true;
                all_Body[i].setAttribute("itselected","true")
            }
        }
        all_Head[0].setAttribute("all","false")
    }else if (all_Head[0].getAttribute("all") == "false"){
        for (let i = 0; i < all_Body.length; i++) {
            if (all_Body[i].getAttribute("itselected") == "true"){
                all_Body[i].checked = false;
                all_Body[i].setAttribute("itselected","false")
            }
        }
        all_Head[0].setAttribute("all","true")
    }
}
function examination() {
    var list_Pages = document.getElementsByClassName("list_Pages")
    for (let i = 0; i < list_Pages.length; i++) {
        if (list_Pages[i].style.display =="block"){
            var number_Pages = document.getElementsByClassName("number_Pages")
            number_Pages[0].innerText = ""+(i+1)
        }
    }
}

function this_All2() {
    var this_All2 = document.getElementsByClassName("this_All2")
    var list_Pages = document.getElementsByClassName("list_Pages");
    var all_Head = document.getElementsByClassName("all_Head")
    if (this_All2[0].checked == false){
        for (let i = 0; i < list_Pages.length; i++) {
            if (list_Pages[i].style.display == "block"){
                var this_ = document.getElementsByClassName("this"+(i+1))
                for (let j = 0; j < this_.length; j++) {
                    this_[j].setAttribute("itselected","false")
                    this_[j].checked = false;
                }
            }
        }
        all_Head[0].setAttribute("all","true")
        all_Head[0].checked = false;
    }else if (this_All2[0].checked == true){
        for (let i = 0; i < list_Pages.length; i++) {
            if (list_Pages[i].style.display == "block"){
                var this_ = document.getElementsByClassName("this"+(i+1))
                for (let j = 0; j < this_.length; j++) {
                    this_[j].setAttribute("itselected","true")
                    this_[j].checked = true;
                }
            }
        }
        var all_Body = document.getElementsByClassName("all_Body")
        var sun = 0;
        for (let i = 0; i < all_Body.length; i++) {
            if (all_Body[i].getAttribute("itselected") == "true"){
                sun+=1;
            }
        }
        if (sun == 15){
            all_Head[0].setAttribute("all","false")
            all_Head[0].checked = true;
        }else{
            all_Head[0].setAttribute("all","true")
            all_Head[0].checked = false;
        }
    }
}
function block(value) {

    var pages = document.getElementsByClassName("list_Pages pages"+value)
    var list_Pages = document.getElementsByClassName("list_Pages")
    for (let i = 0; i < list_Pages.length; i++) {
        list_Pages[i].style.display = "none"
    }
    pages[0].style.display = "block"
    examination()
}